package com.api.client.log;

import org.apache.log4j.Logger;

import com.api.client.Request;
import com.api.client.Response;

public class ApiLogger {

	private static final Logger logger = Logger.getLogger("Api_Request");

	public static void logRequest(Request request) {

		String str = "SENT HTTP Request\n";
		
		str += request.getMethod() + " " + request.getUrl() + "\n";
		
		str += "Headers: " + request.getHeaders() + "\n";

		str += "QueryParams: " + request.getQueryParams() + "\n";

		str += "BodyParams: " + request.getBodyParams() + "\n";
		
		logger.info(str);
	}
	
	public static void logResponse(Request request, Response response) {

		String str = "RECEIVED HTTP Response\n" + request.getMethod() + " " + request.getUrl() + "\n";

		str += "Status: " + response.getStatus() + "\n";

		str += "Body: " +  response.getBody() + "\n";
		
		logger.info(str);
	}

	public static void logSignedRequest(Request request, String accessKey, String accessSecret) {

		String str = "SENT HTTP Signed request\n";
		
		str += request.getMethod() + " " + request.getUrl() + " ('" + accessKey + "','" + accessSecret + "')\n";
				
		logger.info(str);
	}


}
